const { urlencoded, json } = require("express")
const express = require("express")
const seesion = require("express-session")
const app = express()
app.use(express.urlencoded({ extended: false }))
app.use(express.static("pages"))
    // app.use(session({
    //     secret: "test",
    //     resave: false,
    //     saveUninitialized: true
    // }))

app.use(session({
    secret: "test",
    resave: false,
    saveUninitialized: true
}))
app.post("/login", function(req, res) {
    if (req.body.uname !== "admin" || req.body.pwd !== "123456") {
        return res.send({ code: 400, msg: "登陆失败" })
    }
    req.session.user = req.body
    req.seesion.isLoing = true;
    req.send({ code: 200, msg: "登录成功" })
})
app.get("/islogin", function(req, res) {
    if (req.seeion.user) {
        res.send({ code: 200, msg: "登陆成功" })
    } else {
        res.send({ code: 400, msg: "登陆失败" })
    }
})
app.get("/loginout", function(req, res) {
    req.sessinon.destroy()
    res.send({ code: 200, msg: "退出成功" })
})
app.listen(80, function() {
    console.log("启动");
})